---
title: "Mysql Query for Linked List"
date: 2019-5-31
categories:
- mysql
tags:
---

<div id="content">
<blockquote>
<p>
<a href="https://stackoverflow.com/questions/17537043/mysql-query-for-linked-list">https://stackoverflow.com/questions/17537043/mysql-query-for-linked-list</a>
</p>
</blockquote>
<div class="org-src-container">
<pre class="src src-sql"><span style="font-weight: bold;">SELECT</span>  @r <span style="font-weight: bold;">AS</span> _parent,
        @r := (
        <span style="font-weight: bold;">SELECT</span>  id
        <span style="font-weight: bold;">FROM</span>    t_list
        <span style="font-weight: bold;">WHERE</span>   parent = _parent
        ) <span style="font-weight: bold;">AS</span> id
<span style="font-weight: bold;">FROM</span>    (
        <span style="font-weight: bold;">SELECT</span>  @r := 0
        ) vars,
        t_list
</pre>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2019-5-31</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
